package com.jiuyou.clientController.appointment;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jiuyou.clientController.base.ClientBaseController;
import com.ruoyi.appointment.domain.Appointment;
import com.ruoyi.appointment.service.IAppointmentService;
import com.ruoyi.appointmentClose.service.IAppointmentCloseService;
import com.ruoyi.appointmentRecord.domain.AppointmentRecord;
import com.ruoyi.appointmentRecord.service.IAppointmentRecordService;
import com.ruoyi.appointmentSet.domain.AppointmentSet;
import com.ruoyi.appointmentSet.service.IAppointmentSetService;
import com.ruoyi.appointmentSet.vo.ClosesDateVO;
import com.ruoyi.appointmentSet.vo.SeveralWeekVO;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.Member;
import com.ruoyi.common.core.domain.entity.StoreUser;
import com.ruoyi.common.core.domain.entity.StoreUserRole;
import com.ruoyi.common.core.domain.model.LoginMember;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.memberSer.domain.MemberSer;
import com.ruoyi.memberSer.service.IMemberSerService;
import com.ruoyi.product.domain.StoreProduct;
import com.ruoyi.product.service.IStoreProductService;
import com.ruoyi.store.domain.Store;
import com.ruoyi.store.service.IStoreService;
import com.ruoyi.store.service.IStoreUserRoleService;
import com.ruoyi.storeUser.service.IStoreUserService;
import com.ruoyi.storeclassify.domain.Storeclassify;
import com.ruoyi.storeclassify.service.IStoreclassifyService;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.technician.domain.StoreTechnician;
import com.ruoyi.technician.service.IStoreTechnicianService;
import com.ruoyi.wechat.Miniprogram;
import com.ruoyi.wechat.Template;
import com.ruoyi.wechat.TemplateCode;
import com.ruoyi.wechat.TemplateParam;
import com.ruoyi.wechat.util.TokenUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;


@RestController
@RequestMapping("/client/appointment")
public class AppointmentClientController extends ClientBaseController
{
    private static final Logger log = LoggerFactory.getLogger(AppointmentClientController.class);

    @Autowired
    private IStoreProductService storeProductService;
    @Autowired
    private IAppointmentService appointmentService;
    @Autowired
    private IAppointmentCloseService appointmentCloseService;
    @Autowired
    private IAppointmentRecordService appointmentRecordService;
    @Autowired
    private IAppointmentSetService appointmentSetService;
    @Autowired
    private IStoreclassifyService storeclassifyService;
    @Autowired
    private IStoreService storeService;
    @Autowired
    private IStoreTechnicianService technicianService;
    @Autowired
    private IStoreTechnicianService storeTechnicianService;
    @Autowired
    private IMemberSerService memberSerService;
    @Autowired
    private TokenUtil tokenUtil;
    @Autowired
    private ISysConfigService sysConfigService;
    @Autowired
    private IStoreUserRoleService roleService;
    @Autowired
    private IStoreUserService storeUserService;
    /**
     * 返回某个技师某个日期可预约时间
     * @param storeId 门店id
     * @param technicianId 技师id，到点分配传0
     * @param appointmentDate 预约日期
     * @return
     */
    @PostMapping("/listCanAppointmentTimeFrame")
    public AjaxResult listCanAppointmentTimeFrame(Long storeId,Long technicianId, String appointmentDate) {

    //        根据日期获取可以预约的时间列表
        if(null==storeId){
            return AjaxResult.error("");
        }
        if(null==technicianId){
            return AjaxResult.error("");
        }
        if(StringUtils.isEmpty(appointmentDate)){
            return AjaxResult.error("");
        }
        List<Appointment> appointmentList=getAppointListByParams(storeId,technicianId,appointmentDate);
        JSONArray timeList=new JSONArray();
        for (Appointment appointment : appointmentList) {
            JSONObject jso=new JSONObject();
            jso.put("name",appointment.getTimeFrame());
            timeList.add(jso);
        }
        JSONObject jso=new JSONObject();
        jso.put("timeList",timeList);
        return AjaxResult.success(jso);
    }

    private List<Appointment> getAppointListByParams(Long storeId,Long technicianId, String appointmentDate){

    Date appointmentDateD= DateUtils.parseDate(appointmentDate);
    Calendar calendar=DateUtils.dateToCalendar(appointmentDateD);
    int week=calendar.get(Calendar.DAY_OF_WEEK);
    //星期字典值
    String weekDicStr=getWeekStrDic(week);

    //已经有预约记录的时段
    AppointmentRecord appointmentRecordQuery=new AppointmentRecord();
    appointmentRecordQuery.setStoreId(storeId);
    appointmentRecordQuery.setTechnicianId(technicianId);
    appointmentRecordQuery.setAppointmentTime(appointmentDateD);
    appointmentRecordQuery.getParams().put("appointmentStatusUEQ",DicConstants.APPOINTMENT_cancel.getCode());
    List<AppointmentRecord>  appointmentRecordList=  appointmentRecordService.selectAppointmentRecordList(appointmentRecordQuery);
    List<String> stringList=appointmentRecordList.stream().map(AppointmentRecord::getTimeFrame).collect(Collectors.toList());


    Appointment appointmentQuery=new Appointment();
    appointmentQuery.setStoreId(storeId);
    appointmentQuery.setTechnicianId(technicianId);
    appointmentQuery.setSeveralWeeks(weekDicStr);

    if(stringList.size()>0){
        appointmentQuery.getParams().put("timeFrameNOIN",stringList);
    }

    List<Appointment>  appointmentList=appointmentService.selectAppointmentList(appointmentQuery);
    Date now=new Date();
    if(DateUtils.dateTime(now).equals(appointmentDate)){
        //当天只能预约一个小时以后的
        String hhStr=DateUtils.parseDateToStr(DateUtils.HH,now);
        String mmStr=DateUtils.parseDateToStr(DateUtils.mm,now);
        int mm=Integer.parseInt(mmStr);
        if(mm>=30){
            mmStr="30";
        }else{
            mmStr="00";
        }
        String canaStr=hhStr+":"+mmStr;
        int canaIndex=time_sort.get(canaStr)+3;
        appointmentList=appointmentList.stream().filter(r->time_sort.get(r.getTimeFrame())>=canaIndex).collect(Collectors.toList());

    }
    appointmentList=appointmentList.stream().sorted(Comparator.comparing(Appointment::getTimeFrame)).collect(Collectors.toList());
    return appointmentList;
}
    /**
     * 返回某个门店某天可预约的技师
     * @param storeId
     * @param appointmentDate
     * @return
     */
    @PostMapping("/listCanAppointmentTechnician")
    public AjaxResult listCanAppointmentTechnician(Long storeId, String appointmentDate) {

        if(null==storeId){
            return AjaxResult.error("");
        }
        if(StringUtils.isEmpty(appointmentDate)){
            return AjaxResult.error("");
        }
        //查出门店下所有的技师
        //所有当天开启预约的技师
        Date appointmentDateD= DateUtils.parseDate(appointmentDate);
        Calendar calendar=DateUtils.dateToCalendar(appointmentDateD);
        int week=calendar.get(Calendar.DAY_OF_WEEK);
        //星期字典值
        String weekDicStr=getWeekStrDic(week);

        StoreTechnician storeTechnicianQuery=new StoreTechnician();
        storeTechnicianQuery.setState(DicConstants.SYS_Y.getCode());
        storeTechnicianQuery.setStoreId(storeId);
        List<StoreTechnician> storeTechnicianList= technicianService.selectStoreTechnicianList(storeTechnicianQuery);
        //该门店所有的技师
        Map<Long,StoreTechnician> storeTechnicianMap= storeTechnicianList.stream().collect(Collectors.toMap(StoreTechnician::getId,Function.identity()));

        AppointmentSet appointmentSetQuery=new AppointmentSet();
        appointmentSetQuery.setStoreId(storeId);
        List<AppointmentSet>  appointmentSetList=appointmentSetService.selectAppointmentSetList(appointmentSetQuery);
        Map<Long,AppointmentSet> appointmentSetMap=appointmentSetList.stream().collect(Collectors.toMap(AppointmentSet::getTechnicianId, Function.identity()));
//      可以选择的
        JSONArray jsoCan=new JSONArray();
//      不可以选择的
        JSONArray jsoDisable=new JSONArray();
//遍历技师
        for (StoreTechnician storeTechnician : storeTechnicianList) {
                Long id=storeTechnician.getId();
                boolean can=true;
                if(appointmentSetMap.containsKey(id)){
                    AppointmentSet appointmentSet=appointmentSetMap.get(id);
                    can=appointmentSetCan(appointmentSet,appointmentDateD,weekDicStr);
                }else{
                    can=false;
                }
                JSONObject jsoT=new JSONObject();
                jsoT.put("techName",storeTechnician.getTechName());
                jsoT.put("techPositional",storeTechnician.getTechPositional());
                jsoT.put("techImage",storeTechnician.getTechImage());
                jsoT.put("canSelect",can);
                jsoT.put("id",storeTechnician.getId());
                if(can){
                    jsoCan.add(jsoT);
                }else{
                    jsoDisable.add(jsoT);
                }
            }

            if(appointmentSetMap.containsKey(0L)){
                AppointmentSet appointmentSet=appointmentSetMap.get(0L);
                //包含到店分配
                boolean can=DicConstants.SYS_Y.getCode().equals(appointmentSet.getAppointmentState());
                if(can){
                    can=appointmentSetCan(appointmentSet,appointmentDateD,weekDicStr);
                }
                JSONObject jsoT=new JSONObject();
                jsoT.put("techName","到店分配");
                jsoT.put("techPositional","");
                jsoT.put("techImage","https://yifeng-1308901251.cos.ap-beijing.myqcloud.com/upload/2022/07/29/6d4dc828-709d-48d7-8d85-d1bee46a2028_thumb.png");
                jsoT.put("canSelect",can);
                jsoT.put("id",0);
                if(can){
                    jsoCan.add(0,jsoT);
                }else{
                    jsoDisable.add(jsoT);
                }
            }
            //不可选择放在后面
        jsoCan.addAll(jsoDisable);
        JSONObject jso=new JSONObject();
        jso.put("jsoCan",jsoCan);
        return AjaxResult.success(jso);
    }

    /**
     *
     * @param appointmentSet
     * @return
     */
    private  boolean appointmentSetCan(AppointmentSet appointmentSet, Date appointmentDateD,String weekDicStr){
        //启用了设置
        //appointmentDate是否有时段，
        String severalWeeksStr=appointmentSet.getSeveralWeeksStr();
        if(!StringUtils.isEmpty(severalWeeksStr)){
            List<SeveralWeekVO> severalWeeks=new ArrayList<SeveralWeekVO>();
            severalWeeks= JSONArray.parseArray(severalWeeksStr,SeveralWeekVO.class);
            List<SeveralWeekVO> severalWeeksFilter=  severalWeeks.stream().filter(r->weekDicStr.equals(r.getWeekKye())&&DicConstants.SYS_Y.getCode().equals(r.getChecked())).collect(Collectors.toList());
            if(severalWeeksFilter.size()==0){
              return false;
            }
        }else{
//                    没有可用日期，数据异常不能预约
            return false;
        }
        // 不可用时间是否包含今天
        String colseDateStr=appointmentSet.getColseDateStr();
        if(!StringUtils.isEmpty(colseDateStr)){
            List<ClosesDateVO> colseDate=new ArrayList<ClosesDateVO>();
            colseDate= JSONArray.parseArray(colseDateStr,ClosesDateVO.class);
            for (ClosesDateVO closesDateVO : colseDate) {
                String startDate= closesDateVO.getStartDate();
                String endDate= closesDateVO.getEndDate();
                Date startDated=DateUtils.parseDateD(startDate);
                Date endDated=DateUtils.parseDateD(endDate);
                if(appointmentDateD.compareTo(startDated)>=0&&appointmentDateD.compareTo(endDated)<=0){
                    //在不可用范围内
                    return false;
                }
            }
        }
        return true;
    }

    /**
     * 取消预约
     * @param id
     * @return
     */
    @PostMapping("/cancelAppointment")
    public AjaxResult cancelAppointment(Long id) {
        LoginMember loginMember= getLoginMember();
        Member member=loginMember.getMember();

        AppointmentRecord appointmentRecord= appointmentRecordService.selectAppointmentRecordById(id);
        if(appointmentRecord.getAppointmentId()!=member.getId()){
            return AjaxResult.unAuthorize();
        }
        if(!DicConstants.APPOINTMENT_init.getCode().equals(appointmentRecord.getAppointmentStatus())){
            AjaxResult.error("取消失败");
        }
        AppointmentRecord appointmentRecordUpdate=new AppointmentRecord();
        appointmentRecordUpdate.setId(id);
        appointmentRecordUpdate.setAppointmentStatus(DicConstants.APPOINTMENT_cancel.getCode());
        appointmentRecordService.updateAppointmentRecord(appointmentRecordUpdate);
        sendAppointment(appointmentRecord,true);

        return AjaxResult.success("取消成功");
    }
        /**
         * 预约
         * @param storeId 门店id
         * @param technicianId 技师id，到点分配传0
         * @param appointmentDate 预约日期
         * @return
         */
    @PostMapping("/appointment")
    public AjaxResult appointment(Long storeId,Long technicianId, String appointmentDate,String appointmentItem,String appointmentRemark,Integer appointmentNum,String timeFrame,String appointmentPhone) {

        LoginMember loginMember= getLoginMember();
        Member member=loginMember.getMember();

        List<Appointment> appointmentList=getAppointListByParams(storeId,technicianId,appointmentDate);
        List<Appointment> checkList=appointmentList.stream().filter(r->r.getTimeFrame().equals(timeFrame)).collect(Collectors.toList());
        if(checkList.size()==0){
            return AjaxResult.error("该时段不可预约");
        }
        Date appointmentDateD= DateUtils.parseDate(appointmentDate);
        Calendar calendar=DateUtils.dateToCalendar(appointmentDateD);
        int week=calendar.get(Calendar.DAY_OF_WEEK);
        //星期字典值
        String weekDicStr=getWeekStrDic(week);
    //        根据日期获取可以预约的时间列表校验一下
        Store store= storeService.selectStoreById(storeId);
//存储预约信息
        Date appointmentTime=DateUtils.parseDate(appointmentDate);
        AppointmentRecord appointmentRecord=new AppointmentRecord();
        appointmentRecord.setAppointmentId(member.getId());
        appointmentRecord.setAppointmentName(member.getNickName());
        appointmentRecord.setStoreId(storeId);
        appointmentRecord.setStoreImg(store.getStoreImage());
        appointmentRecord.setStoreName(store.getStoreName());
        appointmentRecord.setTechnicianId(technicianId);
        appointmentRecord.setAppointmentItem(appointmentItem);
        if(StringUtils.isEmpty(appointmentRemark)){
            appointmentRemark="无";
        }
        appointmentRecord.setAppointmentRemark(appointmentRemark);
        appointmentRecord.setPlatformRemark("");
        appointmentRecord.setAppointmentNum(appointmentNum);
        appointmentRecord.setAppointmentPhone(appointmentPhone);
        appointmentRecord.setTimeFrame(timeFrame);
        appointmentRecord.setAppointmentTime(appointmentTime);
        appointmentRecord.setSeveralWeeks(weekDicStr);
        appointmentRecord.setAppointmentStatus("init");
        appointmentRecordService.insertAppointmentRecord(appointmentRecord);
        sendAppointment(appointmentRecord,false);
        return AjaxResult.success("预约成功");
    }

    /**
     * 发送预约模板消息
     * @param appointmentRecord
     */
    private void sendAppointment(AppointmentRecord appointmentRecord,boolean cancel){
    try{
        Template template = new Template();
        template.setTemplate_id("6sDzH-O2eUgM9MMMf5yDV8Qkhep7rpMcMvgffw2QgV8");
        Long technicianId=appointmentRecord.getTechnicianId();
        Long storeUserId=0L;
        String keyword4="到店分配";
        if(technicianId==0){
//            到店分配
            Long storeId=appointmentRecord.getStoreId();

            StoreUserRole storeUserRolePara=new StoreUserRole();
            storeUserRolePara.setStoreId(storeId);
            List<StoreUserRole>  listStoreUserRole=roleService.selectStoreUserRoleList(storeUserRolePara);
            for (StoreUserRole su:listStoreUserRole) {
                if(DicConstants.STORE_Identity_Manager.getCode().equals(su.getRoleType())){
                    storeUserId=su.getStoreUserId();
                    break;
                }
            }
        }else{
//            技师
            StoreTechnician storeTechnician=technicianService.selectStoreTechnicianById(technicianId);
            Long userRoleId= storeTechnician.getUserRoleId();
            StoreUserRole storeUserRole=roleService.selectStoreUserRoleById(userRoleId);
            storeUserId=storeUserRole.getStoreUserId();
            keyword4=storeTechnician.getTechName();
        }
        StoreUser storeUser=storeUserService.selectStoreUserById(storeUserId);
        MemberSer ser = memberSerService.selectMemberSerByUinonId(storeUser.getUnionId());
        if(null == ser){
            return;
        }
        Date d=appointmentRecord.getAppointmentTime();
        Calendar c= DateUtils.dateToCalendar(d);
        int week=c.get(Calendar.DAY_OF_WEEK);
        String weekStr=getWeekStr(week);
        String dateStr=DateUtils.parseDateToStr(DateUtils.MM_DD,d);
        JSONObject jso=new JSONObject();
        jso.put("appointmentTimeStr",weekStr+" "+dateStr+" "+appointmentRecord.getTimeFrame());

        template.setTouser(ser.getOpenId());
        template.setPage(TemplateCode.AGENT_INDEX);
        List<TemplateParam> params = new ArrayList<>();
        String first="您有一个预约待处理~";
        String keyword1="待处理";
        String remark="如需调整，请及时联系客户更改时间~";
        if(cancel){
            first="您有一个取消预约待查看~";
            keyword1="取消预约";
            remark="如有问题，请及时跟客户沟通~";
        }

        params.add(new TemplateParam("first",first));
        params.add(new TemplateParam("keyword1",keyword1));
        params.add(new TemplateParam("keyword2",appointmentRecord.getAppointmentItem()));
        params.add(new TemplateParam("keyword3",weekStr+" "+dateStr+" "+appointmentRecord.getTimeFrame()));
        params.add(new TemplateParam("keyword4",keyword4));

        params.add(new TemplateParam("remark",remark));
        template.setTemplateParamList(params);
        List<Miniprogram> miniprograms = new ArrayList<>();
        String app_id = sysConfigService.selectConfigByKey("app_id_store");

        miniprograms.add(new Miniprogram("appid",app_id));
        miniprograms.add(new Miniprogram("path","pages/middlePage/middlePage"));
        template.setMiniprogram(miniprograms);
        String token =  tokenUtil.getToken("yqs").getAccessToken();
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
        String content = HttpUtils.sendPost(url, template.toJSON());
        System.out.println(content);
    }catch (Exception e){
        e.printStackTrace();
    }
}
    /**
     * 预约记录
     * @return
     */
    @PostMapping("/listRecord")
    public AjaxResult listRecord() {
    Long memberId=getLoginMemberId();
        AppointmentRecord appointmentRecordQuery=new AppointmentRecord();
        appointmentRecordQuery.setAppointmentId(memberId);
        startPage();
        List<AppointmentRecord> appointmentRecordList= appointmentRecordService.selectAppointmentRecordList(appointmentRecordQuery);
        List<Long> technicianIds=appointmentRecordList.stream().map(AppointmentRecord::getTechnicianId).collect(Collectors.toList());
        Map<Long,String> mapTechName=new HashMap<Long,String>();

        if(technicianIds.size()>0){
            StoreTechnician storeTechnicianQuery=new StoreTechnician();
            storeTechnicianQuery.getParams().put("technicianIds",technicianIds);
            List<StoreTechnician> storeTechnicianList=  storeTechnicianService.selectStoreTechnicianList(storeTechnicianQuery);
            mapTechName=storeTechnicianList.stream().collect(Collectors.toMap(StoreTechnician::getId,StoreTechnician::getTechName));
        }
        mapTechName.put(0L,"到店分配");
        TableDataInfo tableDataInfo= getDataTable(appointmentRecordList);
        List<JSONObject> listJso=new ArrayList<JSONObject>();
        for (AppointmentRecord appointmentRecord : appointmentRecordList) {
            Date d=appointmentRecord.getAppointmentTime();
            Calendar c= DateUtils.dateToCalendar(d);
            int week=c.get(Calendar.DAY_OF_WEEK);
            String weekStr=getWeekStr(week);
            String dateStr=DateUtils.parseDateToStr(DateUtils.MM_DD,d);
            JSONObject jso=new JSONObject();
            jso.put("appointmentTimeStr",weekStr+" "+dateStr+" "+appointmentRecord.getTimeFrame());
            jso.put("technicianName",mapTechName.get(appointmentRecord.getTechnicianId()));
            jso.put("appointmentItem",appointmentRecord.getAppointmentItem());
            jso.put("appointmentNumStr",appointmentRecord.getAppointmentNum()+"人 "+appointmentRecord.getAppointmentPhone());
            jso.put("appointmentStatusStr", DictUtils.getDictLabel("appointment_status",appointmentRecord.getAppointmentStatus()));
            jso.put("appointmentStatus", appointmentRecord.getAppointmentStatus());
            jso.put("storeName",appointmentRecord.getStoreName());
            jso.put("storeId",appointmentRecord.getStoreId());
            jso.put("id",appointmentRecord.getId());
            listJso.add(jso);
        }
        tableDataInfo.setRows(listJso);

        return AjaxResult.success(tableDataInfo);
    }

    /**
     * 返回预约页基本信息
     * @param storeId
     * @return
     */
    @PostMapping("/baseInfo")
    public AjaxResult baseInfo(Long storeId) {


        StoreProduct storeProductQuery=new StoreProduct();
        storeProductQuery.setStoreId(storeId);
        List<StoreProduct>  storeProductList=storeProductService.selectStoreProductList(storeProductQuery);
       List<Long> classifyIds= storeProductList.stream().map(StoreProduct::getClassifyId).collect(Collectors.toList());

        JSONArray classifyList=new JSONArray();
        JSONObject jsoqt=new JSONObject();
        jsoqt.put("name","其它");
        classifyList.add(jsoqt);
        //服务项目，门店下有的项目+其它
        if(classifyIds.size()>0){
            Storeclassify storeclassifyQuery=new Storeclassify();
            storeclassifyQuery.setState(DicConstants.SYS_Y.getCode());
            storeclassifyQuery.getParams().put("ids",classifyIds);
            List<Storeclassify> storeclassifyList = storeclassifyService.selectStoreclassifyList(storeclassifyQuery);
            for (Storeclassify storeclassify : storeclassifyList) {
                if(storeclassify.getParentId()!=0){
                    JSONObject jso=new JSONObject();
                    jso.put("name",storeclassify.getClassifyName());
                    classifyList.add(jso);
                }
            }
        }

//        到店时间返回最近days天的时间
        JSONArray daysArr=new JSONArray();
        int days=7;
        for (int i=0;i<days;i++){
            JSONObject jso=new JSONObject();
            Calendar c= DateUtils.addDateRCalendar(i);
            Date d=c.getTime();
            String dateStr=DateUtils.parseDateToStr(DateUtils.MM_DD,d);
            String appointmentDate=DateUtils.dateTime(d);
            String weekStr="";
            if(i==0){
                weekStr="今天";
            }else if(i==1){
                weekStr="明天";
            }else{
                int week=c.get(Calendar.DAY_OF_WEEK);
                weekStr=getWeekStr(week);
            }
            jso.put("appointmentDate",appointmentDate);
            jso.put("weekStr",weekStr);
            jso.put("dateStr",dateStr);
            daysArr.add(jso);
        }

        JSONObject jso=new JSONObject();
        jso.put("classifyList",classifyList);
        jso.put("daysArr",daysArr);

        return AjaxResult.success(jso);
    }

    /**
     * 是否显示预约入口
     * @param storeId
     * @return
     */
    @PostMapping("/showAppointment")
    public AjaxResult showAppointment(Long storeId) {
        //门店下有启用的预约设置
        AppointmentSet appointmentSetQuery=new AppointmentSet();
        appointmentSetQuery.setStoreId(storeId);
        appointmentSetQuery.setAppointmentState(DicConstants.SYS_Y.getCode());
        List<AppointmentSet> appointmentSetList= appointmentSetService.selectAppointmentSetList(appointmentSetQuery);

        JSONObject jso=new JSONObject();
        String show= appointmentSetList.size()>0?DicConstants.SYS_Y.getCode() : DicConstants.SYS_N.getCode();
        jso.put("show",show);
    return AjaxResult.success(jso);
    }
    private String getWeekStr(int week){
        String weekStr="";
        switch (week){
            case Calendar.MONDAY:
                weekStr="星期一";
                break;
            case Calendar.TUESDAY:
                weekStr="星期二";
                break;
            case Calendar.WEDNESDAY:
                weekStr="星期三";
                break;
            case Calendar.THURSDAY:
                weekStr="星期四";
                break;
            case Calendar.FRIDAY:
                weekStr="星期五";
                break;
            case Calendar.SATURDAY:
                weekStr="星期六";
                break;
            case Calendar.SUNDAY:
                weekStr="星期日";
                break;
        }
        return weekStr;
    }
    private String getWeekStrDic(int week){
        String weekStr="";
        switch (week){
            case Calendar.MONDAY:
                weekStr="monday";
                break;
            case Calendar.TUESDAY:
                weekStr="tuesday";
                break;
            case Calendar.WEDNESDAY:
                weekStr="wednesday";
                break;
            case Calendar.THURSDAY:
                weekStr="thursday";
                break;
            case Calendar.FRIDAY:
                weekStr="friday";
                break;
            case Calendar.SATURDAY:
                weekStr="saturday";
                break;
            case Calendar.SUNDAY:
                weekStr="sunday";
                break;
        }
        return weekStr;
    }
    //C端需要的接口
//    返回预约的日期和星期，返回可预约项目，返回技师列表
//    门店 +技师+日期返回可预约时段列表
//     门店 +技师+日期确认预约 重新校验可预约时段
//    我的预约记录

    /**
     * 时间排序map
     */
    private static Map<String,Integer> time_sort=new LinkedHashMap<String,Integer>(){
        {
            put("00:00",1); put("00:30",2);
            put("01:00",3); put("01:30",4);
            put("02:00",5); put("02:30",6);
            put("03:00",7); put("03:30",8);
            put("04:00",9); put("04:30",10);
            put("05:00",11); put("05:30",12);
            put("06:00",13); put("06:30",14);
            put("07:00",15); put("07:30",16);
            put("08:00",17); put("08:30",18);
            put("09:00",19); put("09:30",20);
            put("10:00",21); put("10:30",22);
            put("11:00",23); put("11:30",24);
            put("12:00",25); put("12:30",26);
            put("13:00",27); put("13:30",28);
            put("14:00",29); put("14:30",30);
            put("15:00",31); put("15:30",32);
            put("16:00",33); put("16:30",34);
            put("17:00",35); put("17:30",36);
            put("18:00",37); put("18:30",38);
            put("19:00",39); put("19:30",40);
            put("20:00",41); put("20:30",42);
            put("21:00",43); put("21:30",44);
            put("22:00",45); put("22:30",46);
            put("23:00",47); put("23:30",48);
        }
    };
    /**
     * 时间排序map
     */
    private static Map<Integer,String> sort_time=new LinkedHashMap<Integer,String>(){
        {
            put(1,"00:00"); put(2,"00:30");
            put(3,"01:00"); put(4,"01:30");
            put(5,"02:00"); put(6,"02:30");
            put(7,"03:00"); put(8,"03:30");
            put(9,"04:00"); put(10,"04:30");
            put(11,"05:00"); put(12,"05:30");
            put(13,"06:00"); put(14,"06:30");
            put(15,"07:00"); put(16,"07:30");
            put(17,"08:00"); put(18,"08:30");
            put(19,"09:00"); put(20,"09:30");
            put(21,"10:00"); put(22,"10:30");
            put(23,"11:00"); put(24,"11:30");
            put(25,"12:00"); put(26,"12:30");
            put(27,"13:00"); put(28,"13:30");
            put(29,"14:00"); put(30,"14:30");
            put(31,"15:00"); put(32,"15:30");
            put(33,"16:00"); put(34,"16:30");
            put(35,"17:00"); put(36,"17:30");
            put(37,"18:00"); put(38,"18:30");
            put(39,"19:00"); put(40,"19:30");
            put(41,"20:00"); put(42,"20:30");
            put(43,"21:00"); put(44,"21:30");
            put(45,"22:00"); put(46,"22:30");
            put(47,"23:00"); put(48,"23:30");
        }
    };
}
